#include "../BBE.h"
#include "../Image/ImageLib.h"
using namespace ImageLib;
HTEXTURE CALL TextureCreate(int nWidth,int nHeight)
{
	if (nWidth == 0 || nHeight == 0) return NULL;
	Image* pBmpPtr = new Image;
	if (NULL == pBmpPtr) return NULL;
	if (false == pBmpPtr->CreateImage(nWidth,nHeight))
	{
		delete pBmpPtr;
		return NULL;
	}
	return (HTEXTURE)pBmpPtr;
}
HTEXTURE CALL TextureFrom(int nWidth,int nHeight,HTEXTURE hTex,int tx,int ty,int tw,int th)
{
	if (NULL == hTex) return NULL;
	Image* pBmpPtr = new Image;
	if (NULL == pBmpPtr) return NULL;
	if (nWidth == 0 || nHeight == 0)
	{
		if (false == pBmpPtr->CreateImage(tw,th))
		{
			delete pBmpPtr;
			return NULL;
		}
	}
	else 
	{
		if (false == pBmpPtr->CreateImage(tw,th))
		{
			delete pBmpPtr;
			return NULL;
		}
	}
	return (HTEXTURE)pBmpPtr;
}
HTEXTURE CALL TextureLoad(LPCTSTR lpszFileName)
{
	if (!lpszFileName || *lpszFileName == 0)
	{
		return NULL;
	}
	Image* pResPtr = new Image;
	if (NULL == pResPtr) return NULL;
	pResPtr = GetImage(lpszFileName);
	return (HTEXTURE)pResPtr;
}
void CALL TextureRelease(HTEXTURE hTex)
{
	Image* pBmpPtr = (Image*)hTex;
	if (NULL != pBmpPtr) delete pBmpPtr;
}
int  CALL TextureWidth(HTEXTURE hTex)
{
	Image* pBmpPtr = (Image*)hTex;
	if (NULL == pBmpPtr) return 0;
	else return pBmpPtr->GetWidth();
}

int CALL TextureHeight(HTEXTURE hTex)
{
	Image* pBmpPtr = (Image*)hTex;
	if (NULL == pBmpPtr) return 0;
	else return pBmpPtr->GetHeight();
}
DWORD* CALL TextureLock(HTEXTURE hTex,BOOL bReadOnly/*=TRUE*/)
{
	Image* pBmpPtr = (Image*)hTex;
	if (pBmpPtr ==NULL)	return NULL;
	else	return (DWORD*)pBmpPtr->GetBits();
}
void CALL TextureUnLock(HTEXTURE hTex)
{

}